TimeConstrained
TimeConstrained[expr,t] evaluates expr, stopping after t seconds.
TimeConstrained[expr,t,failexpr] returns failexpr if the time constraint is not met.
Please visit the official Wolfram Language Reference for more details and examples on core symbols.